Test 42
Hi There. Welcome to Nirvana, the open source javascript library that allows you to easily perform actions through the mediawiki api. It fetches tokens, performs every non WMF specific (like pagetriage and articlefeedbackv5) action and performs a few queries. This page explains the documentation for this program. Ajax Nirvana uses a jQuery based, mediawiki specific ajax function known as Nirvana.ajax. It offers the parameters: :*Type- this can be used as either get or post and is used to determine the type of request made. Only the arguments get or post are accepted. :*URL- This is the URL of the request. Leave out the API and format part, those are already included. The format always used is JSON to keep up with modern standards. An example URL would be just '?action=logout'. That would be all needed, no mw.util.wikiScript('api') or anything like that. :*Token- This is the token that is to be fetched. This should be provided in an array, with the token as the first part and the target (pagename or user depending on the token) as the second part. Eg: 'User:Kangaroopower'. If it is a post request and no token is to be received, put false (no quotes) as the argument value. For get requests, this replaces the callback argument, which will no longer exist. :*Callback- this should be either an already existing function (like document.location.reload) or literal functional notation- function (data) { //code }. In the functional notation, data refers to the ajax response. Note that for the predetermined functions, I left out ();. This is because Nirvana will do that for you by itself, in order to stop any potential bugs. Example: This is an example usage of this with examples for get and post :*Get: Nirvana.ajax("get", '?action=query&list=usercontribs&ucuser=A', callback); :*In this get would be the type, the '?action=query.... the url and callback being in the tokens argument spot but used as a callback function because it's a get argument. :*Post with token: Nirvana.ajax("post", '?action=edit&title=A&summary=test&text=text', 'A', callback); :*In this post argument, the type is post, the url is a url for editing the page "A" and the token is an array- 'A'. The array's first part controls the type of token it's being used on. The array's second part controls the affected page. And then there's the callback function which controls what you do afterwards. :*Post with token: Nirvana.ajax("post", '?action=logout', false, callback); :*In some cases, like logout, you don't need a token. In these cases, replacing the token value with false will allow go forward with the function, without any tokens. Tokens Nirvana fetches tokens through ?action=tokens for most tokens and for all others, it performs a special, token specific function to retrieve it. The following documentation provides info on the two functions used- Nirvana.getToken and Nirvana.specialToken. You should never, ever, use Nirvana.specialToken. That is an internal function and will be made private soon. Below I will provide examples on how to use Nirvana.getToken. Nirvana.getToken relies on two arguments, token and targ. The token is the type of token used and the targ is the page being identified. Both arguments must be strings, or a value representing a string. Note that the following tokens are the only ones currently supported: edit, rollback, move, protect, delete, block, unblock, undelete, email, import, watch, options, and userrights. Currently, the only "major" token that is unsupported is patrol, although that will come soon. Example: Nirvana.getToken('edit', 'User:Kangaroopower');. This returns the token for editing through the API on User:Kangaroopower. You could always use the default edit action though ;). Actions This is the pièce de résistance for Nirvana. Nirvana provides a built-in API shortcut for mostly every non-WMF specific action that requires a token plus a few others. Check them out. Edit